import { DEVICE_TYPE } from '@/utils/constant'

const { body } = document
const WIDTH = 992 // refer to Bootstrap's responsive design

export const detectDeviceType = () =>
    /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)
        ? DEVICE_TYPE.MOBILE
        : DEVICE_TYPE.PC

export function isMobile() {
    const rect = body.getBoundingClientRect()
    return rect.width - 1 < WIDTH || detectDeviceType() === DEVICE_TYPE.MOBILE
}
